/// ANES Aanalysis for Zingher POBE 2021
/// Requires the Updated Version of Nick Winters' combomarginsplot.ado
/// Download and install the ado before running do file


clear all
* Specify working directory here *  
use "Group Bases", clear


/// Economic orientations regression and figure  1
                     
regress F1_Adj i.race_4##c.PID_7 i.race_4cat##i.female  i.race_4cat##i.South i.race_4cat##i.BA  i.race_4cat##c.Income i.race_4cat##c.rescale_age i.race_4cat##i.unionmember i.race_4cat##i.weeklychurch i.race_4cat##i.Protestant i.race_4cat##i.Catholic i.race_4cat##i.Evangelical i.race_4cat##nonreligious i.race_4cat##c.InOutDifference i.year [pw=VCF0010z] if year>=2000
outreg2 using Econ, replace auto(2) drop(2004.year 2008.year 2012.year 2016.year) dec(2) alpha(.05) symbol(*)
margins, dydx(PID_7) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF1, replace) 
margins, dydx(female) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF2, replace)
margins, dydx(South) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF3, replace) 
margins, dydx(BA) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF4, replace) 
margins, dydx(Income) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF5, replace) 
margins, dydx(rescale_age) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF6, replace) 
margins, dydx(unionmember) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF7, replace) 
margins, dydx(weeklychurch) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF8, replace) 
margins, dydx(Protestant) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF9, replace) 
margins, dydx(Catholic) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF10, replace) 
margins, dydx(Evangelical) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF11, replace)
margins, dydx(nonreligious) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF12, replace)
margins, dydx(InOutDifference) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileEF13, replace) 

combomarginsplot fileEF1 fileEF2 fileEF3 fileEF4 fileEF5 fileEF6 fileEF7 fileEF8 fileEF9 fileEF10 fileEF11 fileEF12 fileEF13, ///
	labels("PID" "Gender" "South" "BA" "Income" "Age" "Union" "Weekly Church" "Protestant" "Catholic" "Evangelical" "Non-religious" "In-group Rating") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal Effect of Group Memberships") title("Economic Attitudes") ///
	legend(pos(6) row(1)) xsize(8) ysize(6) xlabel(-.5(.25).5) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0) col(black)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	plot4opts(mcolor(gs5) mlcolor(black)) ci4opts(msize(0) col(black)) ///
	offset(0.2)
graph save "Economic", replace
graph export "Econonmic.pdf", replace 

/// social policy orientations regression and figure 2
	
regress F2_Adj  i.race_4##c.PID_7 i.race_4cat##i.female  i.race_4cat##i.South i.race_4cat##i.BA  i.race_4cat##c.Income i.race_4cat##c.rescale_age i.race_4cat##i.unionmember i.race_4cat##i.weeklychurch i.race_4cat##i.Protestant i.race_4cat##i.Catholic i.race_4cat##i.Evangelical i.race_4cat##nonreligious i.race_4cat##c.InOutDifference i.year [pw=VCF0010z] if year>=2000
outreg2 using Econ, append auto(2) drop(2004.year 2008.year 2012.year 2016.year) dec(2) alpha(.05) symbol(*)
margins, dydx(PID_7) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF1, replace) 
margins, dydx(female) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF2, replace)
margins, dydx(South) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF3, replace) 
margins, dydx(BA) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF4, replace) 
margins, dydx(Income) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF5, replace) 
margins, dydx(rescale_age) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF6, replace) 
margins, dydx(unionmember) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF7, replace) 
margins, dydx(weeklychurch) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF8, replace) 
margins, dydx(Protestant) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF9, replace) 
margins, dydx(Catholic) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF10, replace) 
margins, dydx(Evangelical) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF11, replace) 
margins, dydx(nonreligious) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF12, replace)
margins, dydx(InOutDifference) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(fileSF13, replace) 


combomarginsplot fileSF1 fileSF2 fileSF3 fileSF4 fileSF5 fileSF6 fileSF7 fileSF8 fileSF9 fileSF10 fileSF11 fileSF12 fileSF13, ///
	labels("PID" "Gender" "South" "BA" "Income" "Age" "Union" "Weekly Church" "Protestant" "Catholic" "Evangelical" "Non-religious" "In-group Rating") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal Effect of Group Memberships") title("Social Attitudes") ///
	legend(pos(6) row(1)) xsize(8) ysize(6) xlabel(-1(.5)1) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0) col(black)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	plot4opts(mcolor(gs5) mlcolor(black)) ci4opts(msize(0) col(black)) ///
	offset(0.2)	
graph save "Social", replace
graph export "Social.pdf", replace 

/// partisanship analysis regression and figure 3

regress PID_7 i.race_4##c.F1_Adj i.race_4##c.F2_Adj i.race_4cat##i.female  i.race_4cat##i.South i.race_4cat##i.BA  i.race_4cat##c.Income i.race_4cat##c.rescale_age i.race_4cat##i.unionmember i.race_4cat##i.weeklychurch i.race_4cat##i.Protestant i.race_4cat##i.Catholic i.race_4cat##i.Evangelical i.race_4cat##nonreligious  i.race_4cat##c.InOutDifference i.year [pw=VCF0010z] if year>=2000
outreg2 using Econ, append auto(2) drop(2004.year 2008.year 2012.year 2016.year) dec(2) alpha(.05) symbol(*)

margins, dydx(F1_Adj) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF1, replace) 
margins, dydx(F2_Adj) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF2, replace)
margins, dydx(female) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF3, replace)
margins, dydx(South) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF4, replace) 
margins, dydx(BA) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF5, replace) 
margins, dydx(Income) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF6, replace) 
margins, dydx(rescale_age) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF7, replace) 
margins, dydx(unionmember) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF8, replace) 
margins, dydx(weeklychurch) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF9, replace) 
margins, dydx(Protestant) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF10, replace) 
margins, dydx(Catholic) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF11, replace) 
margins, dydx(Evangelical) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF12, replace) 
margins, dydx(nonreligious) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF13, replace)
margins, dydx(InOutDifference) at(race_4cat=(1 2 3 4)) predict(xb) level(90) saving(filePF14, replace) 


combomarginsplot filePF1 filePF2 filePF3 filePF4 filePF5 filePF6 filePF7 filePF8 filePF9 filePF10 filePF11 filePF12 filePF13 filePF14, ///
	labels("Econ" "Soc" "Gender" "South" "BA" "Income" "Age" "Union" "Weekly Church" "Protestant" "Catholic" "Evangelical" "Non-religious" "In-group Rating") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal Effect of Group Memberships") title("Party ID") ///
	legend(pos(6) row(1)) xsize(8) ysize(6) xlabel(-1(.5)1) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0) col(black)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	plot4opts(mcolor(gs5) mlcolor(black)) ci4opts(msize(0) col(black)) ///
	offset(0.2)	
graph save "PID", replace
graph export "PID.pdf",replace 

/// vote choice analysis regression and figure 4

logit Pres_Vote i.race_4##c.PID_7 i.race_4##c.F1_Adj i.race_4##c.F2_Adj i.race_4cat##i.female  i.race_4cat##i.South i.race_4cat##i.BA  i.race_4cat##c.Income i.race_4cat##c.rescale_age i.race_4cat##i.unionmember i.race_4cat##i.weeklychurch i.race_4cat##i.Protestant i.race_4cat##i.Catholic i.race_4cat##i.Evangelical i.race_4cat##nonreligious  i.race_4cat##c.InOutDifference i.year [pw=VCF0010z] if year>=2000
outreg2 using Econ, append auto(2) drop(2004.year 2008.year 2012.year 2016.year) dec(2) alpha(.05) symbol(*)
estat ic 

margins, dydx(PID_7) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF1, replace) 
margins, dydx(F1_Adj) at(race_4cat=(1 2 3 4)) level(90) saving(fileVF2, replace) 
margins, dydx(F2_Adj) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF3, replace)
margins, dydx(female) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF4, replace)
margins, dydx(South) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF5, replace) 
margins, dydx(BA) at(race_4cat=(1 2 3 4)) level(90) saving(fileVF6, replace) 
margins, dydx(Income) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF7, replace) 
margins, dydx(rescale_age) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF8, replace) 
margins, dydx(unionmember) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF9, replace) 
margins, dydx(weeklychurch) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF10, replace) 
margins, dydx(Protestant) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF11, replace) 
margins, dydx(Catholic) at(race_4cat=(1 2 3 4)) level(90) saving(fileVF12, replace) 
margins, dydx(Evangelical) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF13, replace)
margins, dydx(nonreligious) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF14, replace) 
margins, dydx(InOutDifference) at(race_4cat=(1 2 3 4))  level(90) saving(fileVF15, replace) 


	
combomarginsplot fileVF1 fileVF2 fileVF3 fileVF4 fileVF5 fileVF6 fileVF7 fileVF8 fileVF9 fileVF10 fileVF11 fileVF12 fileVF13 fileVF14 fileVF15, ///
	labels("Party ID" "Econ" "Soc" "Gender" "South" "BA" "Income" "Age" "Union" "Weekly Church" "Protestant" "Catholic" "Evangelical" "Non-religious" "In-group Rating") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal Effect of Group Memberships on Prob Dem Vote") title("Vote Choice") ///
	legend(pos(6) row(1)) xsize(9) ysize(6) xlabel(-.2(.05).2) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0) col(black)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	plot4opts(mcolor(gs5) mlcolor(black)) ci4opts(msize(0) col(black)) ///
	offset(0.2) xline(-6 4, lc(white) lp(solid))	
	
graph save "Vote Choice", replace
graph export "Vote Choice.pdf", replace 
